package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.Area;
import io.renren.entity.Ditu;
import io.renren.service.AreaService;
import io.renren.service.DituService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 
 * 
 * @author zk
 * @email zk13899@163.com
 * @date 2017-06-14 11:24:56
 */
@Controller
@RequestMapping("area")
public class AreaController {
	@Autowired
	private AreaService areaService;
	@Autowired
	private DituService dituService;
	@RequestMapping("/area.html")
	public String list(){
		return "area/area.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("area:list")
	public R list(Integer page, Integer limit,Integer idMap){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		map.put("idMap", idMap);
		//查询列表数据
		List<Area> areaList = areaService.queryList(map);
		int total = areaService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(areaList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}

	/* 地图列表 */
	@ResponseBody
	@RequestMapping("/ditu/list")

	public R deptlist() {
		Map<String, Object> map = new HashMap<>();
		List<Ditu> listDitu = dituService.queryList(map);

		return R.ok().put("listDitu", listDitu);
	}
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("area:info")
	public R info(@PathVariable("id") Integer id){
		Area area = areaService.queryObject(id);
		
		return R.ok().put("area", area);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("area:save")
	public R save(@RequestBody Area area){
		areaService.save(area);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("area:update")
	public R update(@RequestBody Area area){
		areaService.update(area);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("area:delete")
	public R delete(@RequestBody Integer[] ids){
		areaService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
